﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x0200009D RID: 157
public class MapMob : MonoBehaviour
{
	// Token: 0x0600050C RID: 1292 RVA: 0x0001D87C File Offset: 0x0001BA7C
	private void Start()
	{
		for (int i = 0; i < this.voiceSets.Length; i++)
		{
			for (int j = 0; j < this.voiceSets[i].clips.Length; j++)
			{
				this.voiceList.Add(new ClipAndVoiceType(i, this.voiceSets[i].clips[j]));
			}
		}
		for (int k = 0; k < this.mouthPos.Length; k++)
		{
			int id = this.mouthPos[k].id;
			if (!this.posDic.ContainsKey(id))
			{
				this.posDic.Add(id, new List<MobPosSet>());
			}
			this.posDic[id].Add(this.mouthPos[k]);
		}
		this.timer = 0f;
		this.isFirst = true;
		this.NextTime();
	}

	// Token: 0x0600050D RID: 1293 RVA: 0x0001D95C File Offset: 0x0001BB5C
	private void Update()
	{
		this.timer -= Time.deltaTime;
		if (this.timer <= 0f)
		{
			this.Voice();
			this.NextTime();
		}
		for (int i = 0; i < this.mouthPos.Length; i++)
		{
			this.mouthPos[i].mouth.volume = ConfigData.VolumeVoice_Mob();
		}
	}

	// Token: 0x0600050E RID: 1294 RVA: 0x0001D9C8 File Offset: 0x0001BBC8
	private void Voice()
	{
		if (this.voiceList.Count <= 0)
		{
			return;
		}
		int index = UnityEngine.Random.Range(0, this.voiceList.Count);
		ClipAndVoiceType clipAndVoiceType = this.voiceList[index];
		this.voiceList.RemoveAt(index);
		int id = clipAndVoiceType.id;
		if (this.posDic.ContainsKey(id))
		{
			List<MobPosSet> list = this.posDic[id];
			int index2 = UnityEngine.Random.Range(0, list.Count);
			MobPosSet mobPosSet = list[index2];
			mobPosSet.mouth.PlayOneShot(clipAndVoiceType.clip);
		}
	}

	// Token: 0x0600050F RID: 1295 RVA: 0x0001DA64 File Offset: 0x0001BC64
	private void NextTime()
	{
		if (this.isFirst)
		{
			this.timer = this.firstTime;
			this.isFirst = false;
		}
		else
		{
			this.timer = UnityEngine.Random.Range(this.nextTimeMin, this.nextTimeMax);
		}
	}

	// Token: 0x040003E8 RID: 1000
	[SerializeField]
	private MobVoiceSet[] voiceSets;

	// Token: 0x040003E9 RID: 1001
	[SerializeField]
	private MobPosSet[] mouthPos;

	// Token: 0x040003EA RID: 1002
	private List<ClipAndVoiceType> voiceList = new List<ClipAndVoiceType>();

	// Token: 0x040003EB RID: 1003
	private Dictionary<int, List<MobPosSet>> posDic = new Dictionary<int, List<MobPosSet>>();

	// Token: 0x040003EC RID: 1004
	private float timer;

	// Token: 0x040003ED RID: 1005
	private bool isFirst = true;

	// Token: 0x040003EE RID: 1006
	[SerializeField]
	private float firstTime = 10f;

	// Token: 0x040003EF RID: 1007
	[SerializeField]
	private float nextTimeMin = 5f;

	// Token: 0x040003F0 RID: 1008
	[SerializeField]
	private float nextTimeMax = 15f;
}
